home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Dave’s Fab Samples ƒ / Left and Right Factors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-18  |  3.2 KB  |  115 lines  |  [TEXT/KAHL]

  1. /****************************************************************************************************
  2.     6/96 bob    Updated #includes to support changed GX Library names.
  3.     
  4.     ©1990 - 1996  Apple Computer, Inc.
  5.     All rights reserved.
  6. ****************************************************************************************************/
  7. #include <Types.h>
  8. #include <QuickDraw.h>
  9. #include <Fonts.h>
  10. #include <Windows.h>
  11. #include <Menus.h>
  12. #include <SegLoad.h>
  13. #include <Memory.h>
  14. #include <Desk.h>
  15.  
  16. #include <GXGraphics.h>
  17. #include "GraphicsLibraries.h"
  18. #include <GXEnvironment.h>
  19.  
  20. #include <GXTypes.h>
  21. #include <GXLayout.h>
  22. #include "LayoutLibrary.h"
  23.  
  24. #include "SampleInterface.h"
  25.  
  26. short MyStrLen(char *x);
  27. static short MyStrLen(x)
  28. char    *x;
  29.     {
  30.     short c = 0;
  31.     while (*x++) c++;
  32.     return c;
  33.     }    /* MyStrLen */
  34.  
  35. void LeftAndRightFactors(WindowPtr sampleWindow)
  36.     {
  37.     /* Variables */
  38.     char                            *myString = "infinity";
  39.     gxGlyphcode                        glyphArray[20];        /* will be enough... */
  40.     gxGlyphJustificationOverride        glyphJustOverride;
  41.     gxLayoutOffsetState                offsetState;
  42.     gxLayoutOptions                    gxLayoutOptions;
  43.     gxLine                            myLine;
  44.     gxPoint                            myPoint;
  45.     gxShape                            layout;
  46.     short                            len, level = 0;
  47.     gxStyle                            myStyle;
  48.     unsigned short                    firstGlyph, secondGlyph;
  49.     gxViewPort                        aViewPort;
  50.     
  51.     /* Initialization */
  52.     
  53.     myPoint.x = ff(30);
  54.     myPoint.y = ff(50);
  55.     
  56.     aViewPort = GXNewWindowViewPort(sampleWindow);
  57.     SetDefaultViewPort(aViewPort);
  58.     
  59.     len = MyStrLen(myString);
  60.     
  61.     InitializeLayoutOptions(&gxLayoutOptions);
  62.     gxLayoutOptions.width = ff(500);
  63.     gxLayoutOptions.just = 0;
  64.     
  65.     myLine.first.x = myLine.last.x = myPoint.x;
  66.     myLine.first.y = 0;
  67.     myLine.last.y = ff(1000);
  68.     GXDrawLine(&myLine);
  69.     
  70.     myLine.first.x = myLine.last.x = myPoint.x + gxLayoutOptions.width;
  71.     GXDrawLine(&myLine);
  72.     
  73.     myStyle = NewLayoutStyle((char *) "\pHoefler Text", ff(50), 0, nil, nil, 0, nil);
  74.     
  75.     layout = GXNewLayout(
  76.         1, &len, (void *) &myString,
  77.         1, &len, &myStyle,
  78.         1, &len, &level,
  79.         &gxLayoutOptions, &myPoint);
  80.     GXDrawShape(layout);
  81.     
  82.     GXGetLayoutGlyphs(layout, glyphArray, nil, nil, nil, nil, nil, nil);
  83.     GXGetOffsetGlyphs(layout, 0, true, &offsetState, &firstGlyph, &secondGlyph);
  84.     glyphJustOverride.glyph = glyphArray[firstGlyph - 1];
  85.     glyphJustOverride.override.growFlags = gxOverrideLimits;
  86.     glyphJustOverride.override.shrinkFlags = 0;
  87.     glyphJustOverride.override.beforeGrowLimit = fixed1;
  88.     glyphJustOverride.override.afterGrowLimit = 0;
  89.     GXSetStyleRunGlyphJustOverrides(myStyle, 1, &glyphJustOverride);
  90.     
  91.     gxLayoutOptions.just = fract1 / 4;
  92.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  93.     GXMoveShape(layout, 0, ff(75));
  94.     GXDrawShape(layout);
  95.     
  96.     gxLayoutOptions.just = fract1 / 2;
  97.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  98.     GXMoveShape(layout, 0, ff(75));
  99.     GXDrawShape(layout);
  100.     
  101.     gxLayoutOptions.just = 3 * (fract1 / 4);
  102.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  103.     GXMoveShape(layout, 0, ff(75));
  104.     GXDrawShape(layout);
  105.     
  106.     gxLayoutOptions.just = fract1;
  107.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  108.     GXMoveShape(layout, 0, ff(75));
  109.     GXDrawShape(layout);
  110.     
  111.     GXDisposeShape(layout);
  112.     GXDisposeStyle(myStyle);
  113.     GXDisposeViewPort(aViewPort);
  114.     }    /* main */
  115.